﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RsCms.Application;
using RsCms.Application.Posts.Dto;

namespace Plugin.RsCms.Controllers
{
	[Route("api/[controller]")]
    [ApiController]
    public class PagesController : ControllerBase
    {
        IPagesAppService pageAppService;
        public PagesController(IPagesAppService pageAppService)
        {

            this.pageAppService = pageAppService;

        }
       
        [HttpGet("list")]
        public async Task< object>  GetListAsync(int page,int pageSize)
        {
            return await pageAppService.PageAsync(page, pageSize);
        }
        
        [HttpGet("detail")]
        public async Task<object> GetDetailAsync(string id)
        {
            return await pageAppService.GetPageInfoAsync(id);
        }

        [Authorize("admin")]
        [HttpPost("edit")]
        public async Task<object> SavePagesAsync([FromBody] PostEditDto dto)
        {
            return await pageAppService.SaveAsync(dto);
        }

        [Authorize("admin")]
        [HttpPost("delete")]
        public async Task<object> DeletePagesAsync(string id)
        {
            await pageAppService.DeleteAsync(id);
            return "ok";
        }
    }
}
